home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / pc / PC Software / picks / HTTrack / httrack-3.22-3.exe / {app} / src / swf / swf2html_interface.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-20  |  2.0 KB  |  70 lines

  1. /*
  2.   Flash (SWF) interface to httrack
  3.   Using the library provided by Macromedia(tm)
  4.   from http://www.macromedia.com/software/flash/download/search_engine/index.html
  5.   See swf2html_license.txt for more information on the license
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include "swf2html_cls.h"
  12.  
  13. #ifdef _WIN32
  14. #define MODEXTERN __declspec(dllexport)
  15. #else
  16. #define MODEXTERN 
  17. #endif
  18.  
  19. extern "C" {
  20.   #include "../htsmodules.h"
  21.   #include "swf2html_interface.h"
  22. };
  23.  
  24. extern "C" MODEXTERN int hts_detect_swf(htsmoduleStruct* str) {
  25.   if (strcmp(str->mime, "application/x-shockwave-flash") == 0) {
  26.     return 1;
  27.   }
  28.   return 0;
  29. }
  30.  
  31. extern "C" MODEXTERN int hts_parse_swf(htsmoduleStruct* str) {
  32.   char linkrel[256];
  33.   if (str && str->size > 0) {
  34.     FILE* fp = fopen(str->filename, "rb");
  35.     str->relativeToHtmlLink = 1;
  36.     str->localLink = linkrel;
  37.     str->localLinkSize = sizeof(linkrel) - 1;
  38.     if (fp) {
  39.       int ret = 0;
  40.       char* buffer = (char*) malloc(str->size);
  41.       if (buffer) {
  42.         str->userdef = buffer;
  43.         if ((int) fread(buffer, 1, str->size, fp) == str->size) {
  44.           Swf2HtmlConverterCallback converter;
  45.                   converter.SetDumpLinks(true);
  46.                   converter.SetDumpText(false);
  47.           if (!converter.ConvertSwf2Html(buffer, str->size, str, (htsmodAddLink) str->addLink)) {
  48.             ret = 0;
  49.             strcpy(str->err_msg, "can't parse swf file: internal module error");
  50.           } else {
  51.             ret = 1;
  52.           }
  53.         } else {
  54.           strcpy(str->err_msg, "can't parse swf file: file read error");
  55.         }
  56.         free(buffer);
  57.       } else {
  58.         strcpy(str->err_msg, "can't parse swf file: can't allocate enough memory");
  59.       }
  60.       fclose(fp);
  61.       return ret;
  62.     } else {
  63.       strcpy(str->err_msg, "can't parse swf file: can't open file");
  64.     }
  65.   } else {
  66.     strcpy(str->err_msg, "can't parse swf file: zero length file");
  67.   }
  68.   return 0;
  69. }
  70.